package dao;

import org.hibernate.Query;

public class LuckyDAOImpl extends LuckyDAO {

    /**
     * 获取抽中某一等级奖项的用户数量
     * @param level
     * @return
     */
    public int getCountByLevel(int level) {
        String sql = "select count(lucky_id) from lucky where level = ?";
        Query query = getCurrentSession().createSQLQuery(sql).setInteger(0, level);
        return  ((Number) query.uniqueResult()).intValue();
    }

    /**
     * 修改状态
     * @param openId
     * @param status
     */
    public void updateStatusByOpenId(String openId, int status) {
        String sql = "update lucky set status = ? where open_id = ?";
        Query query = getCurrentSession().createSQLQuery(sql).setInteger(0, status).setString(1, openId);
        query.executeUpdate();
    }
    
    public int getTypeByOpenId(String openId){
        String sql = "select type from lucky where open_id = ?";
        Query query = getCurrentSession().createSQLQuery(sql).setString(0, openId);
        return  ((Number) query.uniqueResult()).intValue();
    }
    
    public int getCountByType(int type){
        String sql = "select count(*) from lucky where level = 3 and type = ?";
        Query query = getCurrentSession().createSQLQuery(sql).setInteger(0, type);
        return  ((Number) query.uniqueResult()).intValue();
    }
    
}